package com.bawei.common.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import com.blankj.utilcode.util.ToastUtils

/**
 * Author: Jason Zhang
 * Date: 2024/12/12
 * Desc: 基础Fragment
 */
abstract class BaseFragment<VDB: ViewDataBinding> :Fragment() {

    lateinit var mDataBinding: VDB

    override fun onCreateView(inflater: LayoutInflater,container: ViewGroup?, savedInstanceState: Bundle?): View? {
        //获取布局代理对象，并获取根组件
        mDataBinding = DataBindingUtil.inflate(inflater, getLayoutId(), container, false)
        return mDataBinding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        initView()
    }

    /**
     * 弹出Toast提示
     */
    fun showToastMsg(msg: String){
        if (!msg.isNullOrEmpty()){
            ToastUtils.showLong(msg)
        }
    }

    /**
     * 让子类实现并返回布局ID
     */
    abstract fun getLayoutId(): Int

    /**
     * 让子类初始化UI组件
     */
    abstract fun initView()

}